package com.milk.milkmedia.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import com.milk.milkmedia.bean.MusicInfo;
import com.milk.milkmedia.ui.HomePageActivity;

/**
 * Created by 微安 on 2015/7/22.
 */
public class MusicInfoDBHelper extends OrmLiteSqliteOpenHelper{

    private static String DATABASE_NAME = "musicinfo";
    public MusicInfoDBHelper(Context context) {
        super(context, DATABASE_NAME, null , FrameDBHelper.DATABASE_VERSION);
    }

    public MusicInfoDBHelper(Context context, String databaseName, SQLiteDatabase.CursorFactory
            factory, int databaseVersion, int configFileId) {
        super(context, databaseName, factory, databaseVersion, configFileId);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource) {
        try{
            TableUtils.createTableIfNotExists(connectionSource, MusicInfoDB.class);
        }catch (Exception e){
            Log.e(HomePageActivity.Tag,"建立MusicInfo表错误");
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource,
                          int i, int i1) {

        try{
            TableUtils.dropTable(connectionSource, MusicInfo.class,true);
        }
        catch (Exception e)
        {
            Log.e(HomePageActivity.Tag,"更新MusicInfo表错误");
        }
        onCreate(sqLiteDatabase,connectionSource);
    }
}
